export default {
  namespaced: true,
  state: {
    opend: [],
    // 是否使用手风琴模式
    accordion: true
  },
  getters: {
    openList (state) {
      if (state.opend.length === 0) {
        const items = JSON.parse(sessionStorage.getItem('menu__openlist'))
        if (items) {
          state.opend = items
        }
      }
      return state.opend
    }
  },
  mutations: {
    change (state, name) {
      if (state.accordion) {
        if (state.opend.length && state.opend.indexOf(name) > -1) {
          state.opend = []
        } else {
          state.opend = [name + '']
        }
      } else {
        const idx = state.opend.indexOf(name + '')
        if (idx === -1) {
          state.opend.push(name + '')
        } else {
          state.opend.splice(idx, 1)
        }
      }
      sessionStorage.setItem('menu__openlist', JSON.stringify(state.opend))
    }
  }
}
